﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SurvivalMan
{
    /// <summary>
    /// This class creates the enimie
    /// </summary>
    class Enimie
    {
        private int Xposition;
        private int Yposition;
        public int speed;
        public int direction = 0, gameState = 0;
        public Texture2D enimieL, enimieR;
        public SpriteFont eS;
        public Vector2 position;
        public Color[] enimieTextureData;
        /// <summary>
        /// To create an enimie the parameters below are needed.
        /// Parameters explained:
        /// Xpos and Ypos are the starting position of the enimie.
        /// startSpeed are int value of the startingspeed of the enimie.
        /// eL and eR are two texture2D´s of the enime pictures, one for each direction the enimie are facing(left or right).
        /// eS are a spritefont that puts the speed of the enimie on the screen.
        /// </summary>
        /// <param name="Xpos"></param>
        /// <param name="Ypos"></param>
        /// <param name="startSpeed"></param>
        /// <param name="eL"></param>
        /// <param name="eR"></param>
        /// <param name="eS"></param>
        public Enimie(int Xpos, int Ypos, int startSpeed, Texture2D eL, Texture2D eR, SpriteFont eS)
        {
            this.Xposition = Xpos;
            this.Yposition = Ypos;
            this.enimieL = eL;
            this.enimieR = eR;
            this.speed = startSpeed;
            this.eS = eS;

        }

        public int getX() { return Xposition; }
        public int getY() { return Yposition; }
        

        public void setX(int x)
        {
            this.Xposition = x;
        }
        public void setY(int Y)
        {
            this.Yposition = Y;
        }
        /// <summary>
        /// This function handles the drawings that are needed for the enime such as the picture of the enimie and the speed of the enimie.
        /// </summary>
        /// <param name="spritebatch"></param>
        public void draw(SpriteBatch spritebatch, int gameState)
        {
            position = new Vector2(Xposition, Yposition);
            if (gameState == 1)
            {
                if (direction == 0)
                    spritebatch.Draw(enimieL, position, Color.White);
                else if (direction == 1)
                    spritebatch.Draw(enimieR, position, Color.White);

                spritebatch.DrawString(eS, speed.ToString(), new Vector2(565, 445), Color.White);
            }
        }
        /// <summary>
        /// This function handles the movment of the enimie.
        /// The movment of the enimie is not controlable like the player, so this function are fully automated.
        /// The parameters that are needed are the Xposition and Yposition from the player, so the enimie can find and hunt down the player.
        /// </summary>
        /// <param name="playerX"></param>
        /// <param name="playerY"></param>
        public void move(int playerX, int playerY, int gameState)
        {
            if (gameState == 1)
            {
                if (Xposition > playerX)
                {
                    Xposition -= speed;
                    direction = 0;
                }
                else if (Xposition < playerX)
                {
                    Xposition += speed;
                    direction = 1;
                }

                if (Yposition > playerY)
                    Yposition -= speed;
                else if (Yposition < playerY)
                    Yposition += speed;
            }

        }
        /// <summary>
        /// This function handles where the enimie should spawn if it has been hit by the player.
        /// This game have two spawn areas for the enimie so the function uses the random function and choose where to spawn.
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public int randomSpawn(int x)
        {
            Random r = new Random();
            x = r.Next(0,2);

            if(x==0)
            {
                x =50;
                return x;
            }
            else 
            {
                x = 750;
                return x;
            }

        }
    }
}
